#encoding:UTF-8
class Com < ActiveRecord::Base
  has_many :breed
  has_many :diseasedesc
  has_many :mating
  has_many :piginfo
  has_many :vaccine
  has_many :disease

  belongs_to :user

 


  #validate the contents.
  validates_presence_of  :comname, :bossname, :tel, :fax, :www, :email ,:qq, :identity, :addr 
  validates :comname,:length => {:minimum => 4,:maximum => 20,:too_long => "最长不超过20个字符",:too_short=> "最短6个字符"}
  validates :bossname,:length => {:minimum => 2,:maximum => 8,:too_long => "最长不超过8个字符",:too_short=> "最短2个字符"}
  validates :tel,:length => {:minimum => 7,:maximum => 13,:too_long => "最长不超过13个字符",:too_short=> "最短7个字符"}
  validates :fax,:length => {:minimum => 6,:maximum => 20,:too_long => "最长不超过20个字符",:too_short=> "最短6个字符"}         
  validates :www,:length => {:minimum => 4,:maximum => 50,:too_long => "最长不超过50个字符",:too_short=> "最短4个字符"}
  validates :email,:length => {:minimum => 8,:maximum => 50,:too_long => "最长不超过50个字符",:too_short=> "最短8个字符"}
  validates :qq,:length => {:minimum => 6,:maximum => 12,:too_long => "最长不超过12个字符",:too_short=> "最短6个字符"}
  validates :identity,:length => {:minimum => 18,:maximum => 18,:too_long => "身份证为18个字",:too_short=> "身份证为18个字"}
  validates :addr,:length => {:minimum => 5,:maximum => 40,:too_long => "最长不超过40个字符",:too_short=> "最短5个字符"}
 
 
# validates :user_id,:uniqueness => {:case_sensitive => false}
  validates :comname,:uniqueness => {:case_sensitive => false}
# validates :password_confirmation,:presence => true,:if => :same_with_password?                                            

  def img=(pic_field)
	transaction do
	  if pic_field.size > 0 && pic_field.size < 2048000 then
	    @pic_size = pic_field.size
   	    @pic_type = pic_field.content_type.chomp
	    self.headimg = pic_field.read
            logger.error self.headimg.to_s
	  end
	end
  end
 




end
